#ifndef UtilityCard_h
#define UtilityCard_h

#include <SdFat.h>
#include <SPI.h>
#include "StartupControllerCommands.h"
#include "StartupController.h"
#include "pins_arduino.h"
#include "SdInfo.h"

class UtilityCard:public Sd2Card {
	public:
		bool init(uint8_t sckRateID = SPI_FULL_SPEED, uint8_t chipSelectPin = SD_CHIP_SELECT_PIN);
		uint32_t cardSize();
		using Sd2Card::readBlock;
		bool readBlock(uint32_t block, uint8_t* dst);
		using Sd2Card::readCID;
		bool readCID(cid_t* cid);
		using Sd2Card::type;  //Sd2Card private must be changed to protected for this
		int type();
		using Sd2Card::readData;   //Sd2Card private must be changed to protected for this
		bool readData(uint8_t *dst);
		using Sd2Card::readStart;
		bool readStart(uint32_t blockNumber);
		using Sd2Card::writeBlock;
		bool writeBlock(uint32_t blockNumber, const uint8_t* src);
		using Sd2Card::writeData;    //Sd2Card private must be changed to protected for this
		bool writeData(const uint8_t* src);
		using Sd2Card::writeStart;
		bool writeStart(uint32_t blockNumber, uint32_t eraseCount);
		using Sd2Card::writeStop;
		bool writeStop();
		using Sd2Card::setSckRate;
		bool setSckRate(uint8_t sckRateID);

		//TODO: bool readCSD(csd_t* csd) {return readRegister(CMD9, csd); }

		using Sd2Card::erase;
		bool erase(uint32_t firstBlock, uint32_t lastBlock);
		using Sd2Card::eraseSingleBlockEnable;
		bool eraseSingleBlockEnable();

		using Sd2Card::error;
		void error(uint8_t code);

		using Sd2Card::errorCode;
		int errorCode();
		using Sd2Card::errorData;
		int errorData();
bool readStop();
	private:
		bool _transfer(uint8_t byte);
		byte _cTransfer(uint8_t byte);

};
#endif
